package com.itheima.stringdemo;

import java.util.Scanner;

public class StringDemo08 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个串字符：");
        String str = sc.next();
        char[] chars = stringToArr(str);
        String result = arrToString(chars);
        System.out.println(result);
    }

    public static char[] stringToArr(String str) {
        char[] arr = new char[str.length()];
        for (int i = 0; i < str.length(); i++) {
            arr[i] = str.charAt(i);
        }
        return arr;
    }

    public static String arrToString(char[] arr) {
        if(arr == null || arr.length == 0) {
            return "";
        }
        String str = "";
        for (int i = arr.length - 1; i >= 0; i--) {
            str += arr[i];
        }
        return str;
    }
}
